/*
ID: brodyzt1
PROG: gift1
LANG: C++
*/

#include <iostream>
#include <fstream>
#include <string>


using namespace std;

int monPerPerson(int numPeople, int totMoney)
{
    if (numPeople == 0) {
        return 0;
    }
    return ((totMoney - (totMoney % numPeople))/numPeople);
}

int main(int argc, const char * argv[])
{
    ifstream input;
    input.open("gift1.in");
    ofstream output;
    output.open("gift1.out");
    int numPeople;
    int money[10];
    
    int giveAmt = 0;
    int giveNum = 0;
    
    input >> numPeople;
    
    for (int i = 0; i < numPeople; i++) {
        money[i] = 0;
    }
    
    string names[10];
    
    for (int i = 0; i < numPeople; i++) {
        input >> names[i];
    }
    
    for (int i = 0; i < numPeople; i++) {
        string currentName;
        input >> currentName;
        int currentIndex = 0;
        for (int j = 0; j < numPeople; j++) {
            if(currentName == names[j])
            {
                currentIndex = j;
                break;
            }
        }
        input >> giveAmt >> giveNum;
        money[currentIndex] -= giveAmt;
       // output << names[currentIndex] << " change -" << giveAmt << "\n";
        for (int k = 0 ; k < giveNum; k++) {
            if (k == 0) {
                money[currentIndex] += giveAmt % giveNum;
            }
            string currentGiveName;
            input >> currentGiveName;
            for (int l = 0; l < numPeople; l++) {
                if(currentGiveName == names[l])
                {
                    money[l] += monPerPerson(giveNum, giveAmt);
                   //output << names[l] << " change +" << monPerPerson(giveNum, giveAmt) << "\n";
                    break;
                }
            }
            
        }
    }
    
    for (int i = 0; i < numPeople; i++) {
        output << names[i] << " " << money[i] << "\n" ;
    }
    
    input.close();
    output.close();
    return 0;

}

